package com.example.user.elasticsearch;

import com.example.user.domain.announcement.es.AnnouncementES;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.annotations.Query;
import org.springframework.data.elasticsearch.repository.ElasticsearchRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AnnouncementRepository extends ElasticsearchRepository<AnnouncementES, Long> {

    Page<AnnouncementES> findAnnouncementByStatus(Integer status, Pageable pageable);

    @Query("{\"bool\": {\"should\": [{ \"match\": { \"title\": \"?0\" } }, { \"match\": { \"content\": \"?1\" } }], \"minimum_should_match\": 1, \"must\": [{\"term\": {\"status\": \"?2\"}}]}}")
    Page<AnnouncementES> findByTitleOrContentAndStatus(String keywordTitle, String keywordContent, Integer status, Pageable pageable);

    @Query("{\"bool\": {\"should\": [{ \"match\": { \"title\": \"?0\" } }, { \"match\": { \"content\": \"?1\" } }], \"minimum_should_match\": 1}}")
    Page<AnnouncementES> findByTitleOrContent(String keywordTitle, String keywordContent, Pageable pageable);
}
